package com.bootx.entity;

import com.bootx.common.BaseAttributeConverter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import org.hibernate.annotations.Comment;
import org.ini4j.OptionMap;

import java.util.ArrayList;
import java.util.List;

@Entity
public class Tool extends BaseEntity<Long>{

    @Comment("名称")
    @Column(nullable = false,unique = true)
    private String name;

    private String image;

    private String memo;

    @Comment("表单")
    @Column(columnDefinition = "longtext")
    @Convert(converter = FormConverter.class)
    private List<Form> forms = new ArrayList<>();

    private Long viewCount;

    private String path;

    private String title;

    private String description;

    private String type;

    @ManyToOne(fetch = FetchType.LAZY)
    private ToolCategory toolCategory;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public List<Form> getForms() {
        return forms;
    }

    public void setForms(List<Form> forms) {
        this.forms = forms;
    }

    public Long getViewCount() {
        return viewCount;
    }

    public void setViewCount(Long viewCount) {
        this.viewCount = viewCount;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public ToolCategory getToolCategory() {
        return toolCategory;
    }

    public void setToolCategory(ToolCategory toolCategory) {
        this.toolCategory = toolCategory;
    }

    public static class Form {

        private String label;

        /**
         * 1: input
         * 2: textarea
         */
        private Integer type;

        private List<OptionMap> options;

        private Integer maxLength;

        private Boolean isRequired;

        private String placeholder;

        private String defaultValue;

        private Boolean allowCreate;

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }

        public Integer getType() {
            return type;
        }

        public void setType(Integer type) {
            this.type = type;
        }

        public List<OptionMap> getOptions() {
            return options;
        }

        public void setOptions(List<OptionMap> options) {
            this.options = options;
        }

        public Integer getMaxLength() {
            return maxLength;
        }

        public void setMaxLength(Integer maxLength) {
            this.maxLength = maxLength;
        }

        public Boolean getIsRequired() {
            return isRequired;
        }

        public void setIsRequired(Boolean isRequired) {
            this.isRequired = isRequired;
        }

        public String getPlaceholder() {
            return placeholder;
        }

        public void setPlaceholder(String placeholder) {
            this.placeholder = placeholder;
        }

        public String getDefaultValue() {
            return defaultValue;
        }

        public void setDefaultValue(String defaultValue) {
            this.defaultValue = defaultValue;
        }

        public Boolean getAllowCreate() {
            return allowCreate;
        }

        public void setAllowCreate(Boolean allowCreate) {
            this.allowCreate = allowCreate;
        }


        public static class OptionMap {
            private String label;

            private String value;

            public String getLabel() {
                return label;
            }

            public void setLabel(String label) {
                this.label = label;
            }

            public String getValue() {
                return value;
            }

            public void setValue(String value) {
                this.value = value;
            }
        }

    }

    @Converter
    public static class FormConverter extends BaseAttributeConverter<List<Form>> {

    }
}
